﻿<html>
	<head>
		<title>Baidu Music</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
		<script type="text/javascript">
            function getOneSongRealURL(song_url){
                $.get(song_url,
                    function(song_data){
                        var song_dom = $(song_data);
                        //$('#log').val(song_data);
                        var song_links = song_dom.find("td.d a");
                        //alert(song_links.length);
                        //$('#log').val('');
                        song_links.each(
                            function(){
                                var song_title = $(this).text();
                                var song_url = $(this).attr('href');
                                $('#log').val($('#log').val()+"\n"+song_title+','+song_url);
                            }
                        );
                    }
                );
            }
            
            function getOneSongURLs(songs_url){
                $.get("/fetch/", { url: songs_url },
                    function(song_data){
                        var song_dom = $(song_data);
                        //$('#log').val(song_data);
                        var song_links = song_dom.find("td.d a");
                        //alert(song_links.length);
                        //$('#log').val('');
                        song_links.each(
                            function(){
                                var song_title = $(this).text();
                                var song_url = $(this).attr('href');
                                $('#log').val($('#log').val()+"\n"+song_title+','+song_url);
                            }
                        );
                    }
                );
            }
            
            function getSongList(){
                $.get("/fetch/", { url: "http://list.mp3.baidu.com/list/newhits.html" },
                    function(songs_data){
                        //alert("Data Loaded: " + songs_data);
                        //$('#log').html(songs_data);
                        //$('#log').val(songs_data);
                        $('#log').val('');
                        var songs_dom = $(songs_data);
                        var songs_links = songs_dom.find("td a:nth-child(1)");
                        //alert(songs_links.length);
                        
                        var songs_div = $('#songs');
                        songs_links.each(
                            function(){
                                var songs_title = $(this).text();
                                var songs_url = $(this).attr('href');
                                if(songs_title && songs_title!="" && songs_url.indexOf('http://mp3.baidu.com/m?tn=baidump3')==0){
                                    //$('#log').val($('#log').val()+songs_title+","+songs_url+"\n");
                                    var singer = $(this).siblings('a').text();
                                    $(this).removeAttr('target');
                                    $(this).click(
                                        function(event){
                                            //event.cancelBubble = true;
                                            //event.stopPropagation();
                                            getOneSongURLs($(event.target).attr('href'));
                                            return false;
                                        }
                                    );
                                    $(this).html($(this).text()+'-'+singer);
                                    songs_div.append($(this));
                                }
                            }
                        );
                    },
                    'html'
                );
            }
            
            $(function(){
                getSongList();
            });
		</script>
        <style type="text/css">
            #songs a {
                width:300px;
                display:inline;
                float:left;
                border-bottom: solid 1px gold;
            }
        </style>
	</head>
	<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="yes">
        <div id="songs"></div>
        <div><textarea style="width:1500px;height:450px;" id="log"></textarea></div>
	</body>
</html>